<template>
  <el-dialog
      v-model="dialogShow"
      :close-on-click-modal="false"
      title="拒绝"
      width="600px"
      @closed="close"
  >
    <div STYLE="margin-bottom: 10px">
      你拒绝接受此任务，请填写原因:
    </div>

    <el-input v-model="reason" placeholder="请输入原因描述" type="textarea"/>

    <template #footer>
      <div class="dialog-footer">
        <el-button
            class="border-btn"
            size="small"
            @click="close"
        >取消
        </el-button>
        <el-button
            class="main-btn"
            size="small"
            type="primary"
            @click="confirm"
        >确定
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script>
import {defineComponent, getCurrentInstance, inject, reactive, toRefs} from 'vue'

export default defineComponent({
  name: "rejectDialog",
  emits: [
    'success'
  ],
  setup(props, {emit}) {
    const currentInstance = getCurrentInstance()
    const api = inject('api')
    var data = reactive({
      dialogShow: false,
      reason: '',
      id: 0,
    })

    const close = () => {
      data.reason = ''
      data.dialogShow = false
    }

    const confirm = () => {
      if (!data.reason) {
        currentInstance.proxy.customMessage({type: 'error', message: '请输入拒绝原因'})
        return
      }
      api.plan.ALLOCATION_AGENT_DEAL({planDetailId: data.id, type: '2', reason: data.reason}).then(res => {
        if (!res.code) {
          currentInstance.proxy.customMessage({type: 'success', message: '处理成功'})
          emit('success')
          close()
        } else {
          currentInstance.proxy.customMessage({type: 'error', message: res.msg})
        }
      })
    }

    const open = (id) => {
      data.id = id
      data.dialogShow = true
    }

    return {
      ...toRefs(data),

      close,
      confirm,
      open,
    }
  }
})
</script>

<style scoped>

</style>
